<template>
	<view class="refund-detail-container">
		<view class="content">
			<view class="box">
				<view class="refund-title">请填写退货快递单号</view>
				<view class="hint-text">请在<text class="cred">7天</text>内填写快递单号</view>
			</view>
			<view class="box">
				<view class="tip">请正确填写快递单号，以免影响退款进度</view>
				<uv-gap height="10" color="transparnet" />
				<uv-input v-model="model.refund_express" border="none" placeholder="请填写退货快递单号" />
				<uv-gap height="10" color="transparnet" />
			</view>
			<view class="form-item">
				<view class="form-input" @click="showLogistics">
					<text class="placeholder" v-if="model.refund_express_id==0" style="color:#C9CACA;">选择物流公司</text>
					<text v-else>{{logistics_name}}</text>
					<uv-icon name="arrow-right" size="12" />
				</view>
			</view>
			<view class="box">
				<view class="tip">填写退货运费金额</view>
				<uv-gap height="10" color="transparnet" />
				<uv-input v-model="model.refund_express_prices" border="none" placeholder="请输入退货运费金额" />
				<uv-gap height="10" color="transparnet" />
			</view>
		</view>
	</view>
	<view class="footer-btn">
		<button type="button" class="btn_sure" @click="doSubmit">确认提交</button>
	</view>
	<uv-popup ref="popLogisticsRef" mode="bottom" round="10" closeable>
		<chooseLogistics @select="chooseCompany" />
	</uv-popup>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue';
	import {
		fillReturnNumber
	} from '@/api'
	import chooseLogistics from './components/select_logistics.vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	const popLogisticsRef = ref(null)
	const model = reactive({
		after_sales_id: 0,
		refund_express: '',
		refund_express_id: 0,
		refund_express_prices: ''
	})
	const logistics_name = ref('');
	const showLogistics = () => {
		popLogisticsRef.value.open()
	}
	const chooseCompany = (e) => {
		logistics_name.value = e.title
	    model.refund_express_id = e.id
		popLogisticsRef.value.close()
	}
	onLoad((option) => {
		if (!option.after_sales_id) return
		model.after_sales_id = option.after_sales_id
	})
	const doSubmit = async () => {
		if (!model.refund_express) return uni.$uv.toast('请填写退货快递单号')
		if (model.refund_express_id==0) return uni.$uv.toast('请选择物流公司')
		if (!model.refund_express_prices) return uni.$uv.toast('请填写退货运费金额')
		const res = await fillReturnNumber(model)
		if (res.code == 200) {
			uni.navigateTo({
				url: '/pages-home/market/refundform_result'
			})
		} else {
			uni.$uv.toast(res.msg)
		}
	}
</script>

<style lang="scss" scoped>
	.refund-detail-container {
		background-color: #f7f7f7;
		min-height: 100vh;
		padding-bottom: 80px;
	}

	.refund-title {
		color: #333;
		font-size: 36upx;
		font-weight: bold;
		margin-bottom: 6upx;
	}

	.cred {
		color: #ff0000;
	}

	.content {
		padding-top: 10px;

		.box {
			background-color: #fff;
			padding: 10px;
			border-bottom: #eee 1px solid;

			.tip {
				font-size: 30upx;
				color: #333;
			}
		}
	}

	.refund-form {
		display: flex;
		flex-direction: column;
		gap: 15px;
	}

	.form-item {
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 20upx;
		border-bottom: 1upx solid #eee;

		&:last-child {
			border-bottom: none;
		}
	}

	.form-label {
		font-size: 28upx;
		margin-right: 20upx;
	}

	.form-input {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 28upx;
		padding: 10upx 0;
	}

	.hint-text {
		color: #666;
		font-size: 26upx;
		margin: 0;
	}

	.footer-btn {
		bottom: 0;
		width: 100%;
		z-index: 10;
		display: flex;
		padding: 30upx;
		position: fixed;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
		background-color: #fff;
		.btn_sure {
			display: flex;
			flex: 1;
			justify-content: center;
			align-items: center;
			height: 80upx;
			line-height: 80upx;
			border-radius: 40upx;
			background-color: #DE3F27;
			color: #fff;
			font-size: 28upx;
		}
	}
</style>